package com.zj.study.filter;

import com.zj.study.config.properties.JwtConfigurationProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 赵赳
 * @since 2021/12/15 9:50
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

  JwtConfigurationProperty jwtConfigurationProperty;

  @Autowired
  public void setJwtConfigurationProperty(
      JwtConfigurationProperty jwtConfigurationProperty) {
    this.jwtConfigurationProperty = jwtConfigurationProperty;
  }

  /**
   * 拦截器注册
   *
   * @param registry 拦截器注册器
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    var webHandlerInterceptor = new WebHandlerInterceptor(jwtConfigurationProperty);
    registry.addInterceptor(webHandlerInterceptor).addPathPatterns("/**");
  }

}
